package com.woniuxy.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.entity.RbacManager;
import com.woniuxy.result.Result;
import com.woniuxy.service.RbacManagerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 管理员表 前端控制器
 * </p>
 *
 * @author linKe
 * @since 2021-11-25
 */
@RestController
@RequestMapping("/rbacManager")
@Api(value="管理员接口",tags="rbacManagerApi")
public class RbacManagerController {
    @Resource
    private RbacManagerService rbacManagerService;

    @GetMapping("/one/{id}")
    @ApiOperation(value="根据ID查询管理员",notes="返回管理员")
    public Result<RbacManager> findOneManagerById(@PathVariable int id){
        return new Result<>("200","ok",rbacManagerService.findOneById(id));
    }
    @GetMapping("/one/all")
    @ApiOperation(value="查询所有管理员",notes="返回所有管理员")
    public Result<List<RbacManager>> findAllManager(){
        return new Result<>("200","ok",rbacManagerService.findAllManager());
    }


    @PostMapping("/one/")
    @ApiOperation(value="新增管理员",notes="返回结果1表示成功，0表示失败")
    public Result<Integer> addManager(RbacManager rbacManager){
        System.out.println(rbacManager);
        return new Result<>("200","ok",rbacManagerService.addManager(rbacManager));
    }

    @PutMapping("/one/")
    @ApiOperation(value="更新管理员",notes="返回结果1表示成功，0表示失败")
    public Result<Integer> updateManager(RbacManager rbacManager){
        int row = rbacManagerService.updateManager(rbacManager);
        return new Result<>("200","ok",row);
    }

    @DeleteMapping("/one/{id}")
    @ApiOperation(value="根据ID删除管理员",notes="返回结果1表示成功，0表示失败")
    public Result<Integer> deleteManager(@PathVariable int id){
        return new Result<>("200","ok",rbacManagerService.deleteManager(id));
    }

    @GetMapping("/findPage/{currentPage}/{size}")
    @ApiOperation(value="无限定条件分页查询",notes="返回分页后的结果集")
    @ApiImplicitParams({
            @ApiImplicitParam(
                    paramType="path",name="currentPage",value="当前页",
                    dataType="Int",required=true),
            @ApiImplicitParam(
                    paramType="path",name="size",value="每页显示条数",
                    dataType="Int",required=true)
    })
    public Result<Page<RbacManager>> findPage(@PathVariable("currentPage") int currentPage, @PathVariable("size") int size){
        return new Result<>("200","ok",rbacManagerService.findAllPage(currentPage,size));
    }



    @PostMapping("/findPageN/")
    @ApiOperation(value="条件分页查询",notes="返回分页后的结果集")
        public Result<Page<RbacManager>> findPageSearch(@RequestParam  Map<String,String> pageInfo){
        System.out.println(pageInfo);

        return new Result<>("200","ok",rbacManagerService.findPageSearch(pageInfo));
    }
}
